<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

			<%@ include file="/include/gnb.jsp"%>
			<!-- Main Start -->
			<div id="maincontainer">
				<!-- LeftMenu Start -->
				<div id="leftmenu">
					<%@ include file="/include/lnb.jsp"%>
				</div>
				<!-- Contants Start -->
				<div id="contants">
					<div class="height_10p"></div>
					<form id="commonForm" name="commonForm" method="post">
						<input type="hidden" id="_groupId" name="_groupId" value="${_groupId}" />
						<input type="hidden" id="_menuId" name="_menuId" value="${_menuId}" />
						<input type="hidden" id="_menuNm" name="_menuNm" value="${_menuNm}" />
						<input type="hidden" id="_menuAuth" name="_menuAuth" value="${_menuAuth}" />
						<input type="hidden" id="_prevUpCode" name="_prevUpCode" value="${_prevUpCode}" />
						<input type="hidden" id="_prevCode" name="_prevCode" value="${_prevCode}" />
					</form>
					<div id="ajaxDivList" class="noborder"></div>
				</div>
				<!-- Contants End -->
			</div>
		</div>
		<!-- Footer Start -->
		<div id="footer">
			<%@ include file="/include/footer.jsp"%>
		</div>
	</div>

<script>
var url = "commonCodeMgmt.action";
var params = "target=cmList";
var targetElement = "ajaxDivList";

var pmModule = {
		loadList: function() {
			var rParams = params + "&" + $("#commonForm").serialize() + ($("#loadCheck").val() == "OK" ? ($("#isNew").val() == "Y" ? "&searchVal1=" + $("#searchVal1").val() : "&" + $("#searchForm").serialize()) : "");

			this.makeList(url, rParams);
		},
		
		setBinding: function() {
		},
		
		setUnbinding: function() {
		},
		
		onSelectGroup: function(groupId) {
			var use = $("#use_" + groupId);
			if (use.val() == "N") {
				alert("해당 그룹을 사용할 수 없습니다. 사용 여부를 변경하여 주십시오.");
				return;
			}
			
			$("#addGroupDiv").hide();
			$("#addCodeDiv").hide();
			this.resetAddGroup();
			this.resetAddCode();
			
			$("#groupForm .selected").removeClass("selected");
			$("#groupForm #group_" + groupId).addClass("selected");
			
			$("#codeForm #codeGroupId").val(groupId);
			
			$("#rMenu").removeClass("nodisplay");
			$("#rMenu .ulMenu").addClass("nodisplay");
			$(".group_" + groupId).removeClass("nodisplay");
			
			$("#_prevUpCode").val(groupId);
		},
		
		onSelectCodeType: function(that) {
			$("#codeForm #codeLink").val("").parent().hide();
			if ($(that).val() == "1") {
				$("#codeForm #codeLink").parent().show();
			}
		},
		
		setAddGroup: function() {
			this.resetAddGroup();
			$("#addGroupDiv").removeClass("nodisplay")
									.css({
										"position":"absolute", 
										"top":($("#rGroup").offset().top + $(".ulPlusMenu").innerHeight()), 
										"width":$("#rGroup").css("width"),
										"border":"1px dotted #666"
									})
									.hide()
									.slideDown(200);
		},
		
		setAddCode: function() {
			this.resetAddCode();
			$("#addCodeDiv").removeClass("nodisplay")
									.css({
										"position":"absolute", 
										"top":($("#rMenu").offset().top + $(".ulPlusMenu").innerHeight()), 
										"width":$("#rMenu").css("width"),
										"border":"1px dotted #666"
									})
									.hide()
									.slideDown(200);
		},
		
		setModifyGroup: function(codeGroupId, codeGroupNm, codeGroupDesc, useYn) {
			this.setAddGroup();
			$("#groupForm #isNew").val("N");
			$("#groupForm #codeGroupId").val(codeGroupId);
			$("#groupForm #codeGroupNm").val(codeGroupNm);
			$("#groupForm #codeGroupDesc").val(codeGroupDesc);
			if (useYn == "N") {
				$("#groupForm #useYn2").click();
			}

			$("#groupForm .selected").removeClass("selected");
			$("#groupForm #group_" + codeGroupId).addClass("selected");
			
			$("#_prevUpCode").val(codeGroupId);
		},

		setModifyCode: function(codeId, codeNm, codeValue, codeDesc, codeType, codeLink, useYn) {
			this.setAddCode();
			$("#codeForm #isNew").val("N");
			$("#codeForm #codeId").val(codeId);
			$("#codeForm #codeNm").val(codeNm);
			$("#codeForm #codeValue").val(codeValue);
			$("#codeForm #codeDesc").val(codeDesc);
			$("#codeForm #codeType").val(codeType);
			$("#codeForm #codeLink").val(codeLink);
			if (useYn == "N") {
				$("#codeForm #useYn2").click();
			}

			$("#codeForm .selected").removeClass("selected");
			$("#codeForm #code_" + codeId).addClass("selected");
			
			$("#_prevCode").val(codeId);
		},

		resetAddGroup: function() {
			$("#groupForm #isNew").val("Y");
			$("#groupForm #codeGroupId").val("");
			$("#groupForm #codeGroupNm").val("");
			$("#groupForm #codeGroupDesc").val("");
			$("#groupForm #useYn1").click();
		},

		resetAddCode: function() {
			$("#codeForm #isNew").val("Y");
			$("#codeForm #codeId").val("");
			$("#codeForm #codeNm").val("");
			$("#codeForm #codeValue").val("");
			$("#codeForm #codeDesc").val("");
			$("#codeForm #codeType").val("");
			$("#codeForm #codeLink").val("");
			$("#codeForm #useYn1").click();
		},
		
		setDeleteGroup: function(groupId) {
			this.getExistCode(groupId);
			if ($("#ajaxResult").val() > 0) {
				alert("해당 그룹에 속해 있는 코드가 있어 삭제가 불가능합니다.");
				return;
			}
			
			if (!confirm("해당 그룹을 삭제합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=cmDeleteGroup&codeGroupId=" + groupId + "&" + $("#commonForm").serialize();

			this.makeList(url, rParams);
		},
		
		setDeleteCode: function(codeId) {
			if (!confirm("해당 코드를 삭제합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=cmDeleteCode&codeId=" + codeId + "" + $("#commonForm").serialize();

			this.makeList(url, rParams);
		},

		cancelGroup: function() {
			$("#addGroupDiv").slideUp(100);
			this.resetAddGroup();
		},

		cancelCode: function() {
			$("#addCodeDiv").slideUp(100);
			this.resetAddCode();
		},

		saveGroup: function() {
			var codeGroupNm = $("#codeGroupNm");
			if (codeGroupNm.val() == "") {
				alert("그룹 이름을 입력하여 주십시오.");
				codeGroupNm.focus();
				return;
			}
			
			if (!confirm("해당 설정을 저장합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=cmSaveGroup&" + $("#commonForm").serialize() + "&" + $("#groupForm").serialize();

			this.makeList(url, rParams);
		},

		saveCode: function() {
			var codeNm = $("#codeNm");
			if (codeNm.val() == "") {
				alert("코드 이름을 입력하여 주십시오.");
				codeNm.focus();
				return;
			}
			
			var codeValue = $("#codeValue");
			if (codeValue.val() == "") {
				alert("코드 값을 입력하여 주십시오.");
				codeValue.focus();
				return;
			}
			
			var codeType = $("#codeType");
			if (codeType.val() == "") {
				alert("코드 유형을 입력하여 주십시오.");
				codeType.focus();
				return;
			}
			
			if (!confirm("해당 설정을 저장합니다. 계속 하시겠습니까?")) {
				return;
			}
			
			var rParams = "target=cmSaveCode&" + $("#commonForm").serialize() + "&" + $("#codeForm").serialize();

			this.makeList(url, rParams);
		},
		
		getExistCode: function(groupId) {
			$.ajax({
				url : url,
				type : "POST",
				data : "target=cmExistCode&codeGroupId=" + groupId,
				dataType : "html",
				async : false,
				success : function(data) {
					$("#ajaxResult").remove();
					$("body").append(data);
				}
			});
		},
		   
		makeList: function(sUrl, sParams) {
			var that = this;
			
			$.ajax({
				url : sUrl,
				type : "POST",
				data : sParams,
				dataType : "html",
				success : function(data){
					$("#" + targetElement).html(data);

					that.setUnbinding();
					that.setBinding();
					that.initPage();

					if ($("#nodata").html() != null) {
					}
				}
			});
		},
		
		initPage: function(){
			this.initPageSize();
		},
		     
		initPageSize: function(){
		    var msg = "";
			
			// warp
			var valueGwpw = getObjectValue("#warp", "width"); 
			var gwpw = (valueGwpw == null) ? 0 : valueGwpw; // 대상 전체 폭
			var valueGwph = getObjectValue("#warp", "height"); 
			var gwph = (valueGwph == null) ? 0 : valueGwph; // 대상 전체 높이
			msg = appendMessage(msg, "#warp");
			
			setObjectValue("#container", "width", Math.round(gwpw - 40));
			
			// container
			var valueGcw = getObjectValue("#container", "width"); 
			var gcw = (valueGcw == null) ? 0 : valueGcw; // 대상 전체 폭
			var valueGch = getObjectValue("#container", "height"); 
			var gch = (valueGch == null) ? 0 : valueGch; // 대상 전체 높이
			msg = appendMessage(msg, "#container");
			
			// contants
			setObjectValue("#contants", "width", Math.round(gcw - 180 - 10));
			msg = appendMessage(msg, "#contants");
			
			// formtitle
			var valueGftw = getObjectValue("#formtitle", "width");
			var gftw = (valueGftw == null) ? 0 : valueGftw; // 대상 전체 폭
			var valueGfth = getObjectValue("#formtitle", "height"); 
			var gfth = (valueGfth == null) ? 0 : valueGfth; // 대상 전체 높이
			
			// formlist
			var valueGccw = getObjectValue("#contants", "width"); 
			var gccw = (valueGccw == null) ? 0 : valueGccw; // 대상 전체 폭
			var valueGcch = getObjectValue("#contants", "height"); 
			var gcch = (valueGcch == null) ? 0 : valueGcch; // 대상 전체 높이
			
			setObjectValue("#formlist3l", "height", Math.round(gcch - gfth - 35));
			setObjectValue("#formlist3r", "height", Math.round(gcch - gfth - 35));
			
			var formw = getObjectValue("#formlist3l", "width"); 
			setObjectValue("#formlist3r", "width", Math.round(gccw - formw - 30));
			msg = appendMessage(msg, "#formlist3r");
			
			$(".LoggingMessage").html(msg);
		}
};

$(document).ready(function(){
	pmModule.loadList();
	pmModule.initPage();
});

$(window).resize(function(){
	pmModule.initPage();
});
</script>
</body>
</html>
